package com.itheima.cases_demo.local_date_time;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Test3 {
    public static void main(String[] args) {
        // 日期时间格式化对象

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");

        LocalDateTime now = LocalDateTime.now();
        System.out.println(now); // 2023-07-30T20:55:15.161849800

        String format = dateTimeFormatter.format(now);
        System.out.println(format); // 2023年07月30日 20:55:52

        // 解析字符串

        String str = "2016-12-12 10:02:00";
        DateTimeFormatter farmat2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime pastTime = LocalDateTime.parse(str, farmat2);
        System.out.println(pastTime); // 2016-12-12T10:02
    }
}
